<?php

namespace app\common\model;

use think\Config;
use think\Model;

/**
 * 会员余额日志模型
 * @property $type 1 消费 3 陪玩师收入 4 代理收益 5 推广收益
 */
class MoneyLog extends Model
{

    // 表名
    protected $name = 'user_money_log';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = '';
    // 追加属性
    protected $append = [
    ];

    public static function add($uid,$money,$type=1,$memo='',$order_no=''){
        $user = User::get($uid);
        $data=[
            'uid'=>$uid,
            'money'=>$money,
            'before'=>$user->money,
            'after'=>$user->money+=$money,
            'type'=>$type,
            'order_no'=>$order_no,
            'memo'=>$memo,
        ];
        MoneyLog::create($data);
        $user->save();
    }
}
